import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:macnov/common/budget_avatar.dart';
import 'package:macnov/common/empty_data.dart';
import 'package:macnov/common/search_box.dart';
import 'package:macnov/models/budget_member.dart';
import 'package:macnov/stores/budget.dart';

class PeopleList extends StatefulWidget {
  @override
  _PeopleListState createState() => _PeopleListState();
}

class _PeopleListState extends State<PeopleList> {
  Widget _buildMembers() {
    return Observer(
        builder: (_) => budgetStore.budgetMember == null
            ? EmptyData()
            : ListView(
                shrinkWrap: true,
                children: budgetStore.budgetMember.members
                    .map(
                      (Member member) => Container(
                          color: Colors.white,
                          child: ListTile(
                            leading: BudgetAvatar(arguments: [member.firstName,member.lastName],),
                            title:
                                Text('${member.firstName} ${member.lastName}'),
                            subtitle: Text(r'$' +
                                '${member.availableAmt} available to spend'),
                            trailing: Icon(Icons.navigate_next),
                          )),
                    )
                    .toList(),
              ));
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: <Widget>[
          Padding(
            padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
            child: SearchBox(),
          ),
          _buildMembers(),
        ],
      ),
    );
  }
}
